Shader "Unlit/unlit1"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _FurLength("_FurLength",Range(0,10))= 1
    }
    SubShader
    {
        Tags
        {
            "RenderType"="Opaque"
        }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma geometry geom
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2g
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            struct g2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
                float4 col : COLOR;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            float _FurLength;

            v2g vert(appdata v)
            {
                v2g o ;
               o.vertex =v.vertex;
                // o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
            }

            [maxvertexcount(9)]
            void geom(triangle v2g IN[3], inout TriangleStream<g2f> tristream)
            {
                g2f o = (g2f)0;

                float3 centerPos = (IN[0].vertex + IN[1].vertex + IN[2].vertex) / 3;
                float3 edgeA = IN[1].vertex - IN[0].vertex;
                float3 edgeB = IN[2].vertex - IN[0].vertex;
                float3 normalFace = normalize(cross(edgeA, edgeB));

                centerPos += (normalFace * (_FurLength/10)); // 直接使用 _FurLength，不再除以 100

                for (int i = 0; i < 3; i++)
                {
                    // o.vertex = IN[i].vertex;
                     o.vertex = UnityObjectToClipPos(IN[i].vertex);
                    o.uv = IN[i].uv;
                    o.col = float4(0.0, 0.0, 1.0, 1.0); // 给毛发一个固定颜色
                    tristream.Append(o);

                  o.vertex =UnityObjectToClipPos(
                      IN[(i + 1) % 3].vertex);

                    // o.vertex = IN[(i + 1) % 3].vertex;
                    o.uv = IN[(i + 1) % 3].uv;
                    o.col = float4(1.0, 0.0, 0.0, 1.0);
                    tristream.Append(o);

                      // o.vertex = centerPos;
                    o.vertex = UnityObjectToClipPos(centerPos);
                    o.uv = (IN[i].uv + IN[(i + 1) % 3].uv) / 2; // 平均纹理坐标
                    o.col = float4(0.0, 1.0, 0.0, 1.0);
                    tristream.Append(o);

                    tristream.RestartStrip();
                }
            }

            fixed4 frag(g2f i) : SV_Target
            {
                return i.col; // 使用几何着色器传递的颜色
            }
            ENDCG
        }
    }
}